﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using App_Code;

public partial class Detail_Product : System.Web.UI.Page
{
    dulieuDataContext db=new dulieuDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        rpt_chitiet.DataSource = from o in db.Products
                                 where o.ProductID == Convert.ToDecimal(Request.QueryString["ma-san-pham"])
                                 select o;
        rpt_chitiet.DataBind();
        var pro=
            (from o in db.Products where o.ProductID == Convert.ToDecimal(Request.QueryString["ma-san-pham"]) select o).
                SingleOrDefault();
        var cate1=(from o in db.Cates where o.Cate_ID == pro.Cate_ID select o).SingleOrDefault();
        if (cate1 != null) lblcon.Text = cate1.Name;
        lblcha.Text = (from o in db.Cates where o.Cate_ID == cate1.Parent select o.Name).SingleOrDefault();
        var sanpham =
            (from o in db.Products where o.ProductID == Convert.ToDecimal(Request.QueryString["ma-san-pham"]) select o).
                SingleOrDefault();
        if (sanpham != null) sanpham.Count = sanpham.Count + 1;
        db.SubmitChanges();
        int cate =Convert.ToInt32((from o in db.Products
                   where o.ProductID == Convert.ToDecimal(Request.QueryString["ma-san-pham"])
                   select o.Cate_ID).SingleOrDefault()) ;
        rpt_san_pham_cung_loai.DataSource = (from o in db.Products orderby o.ProductID descending where o.Cate_ID == cate && o.ProductID != Convert.ToDecimal(Request.QueryString["ma-san-pham"]) select o).Take(9);
        rpt_san_pham_cung_loai.DataBind();
    }
    protected void BuyClick(object s, CommandEventArgs e)
    {
        var idpr = e.CommandName;
        var cart = (Cart)Session["cart"];
        if (cart == null)
        {
            cart = new Cart();
        }
        cart.AddPro(idpr, 1);
        Session.Add("cart", cart);
        Response.Write("<SCRIPT language='JavaScript'>alert('Đã thêm vào giỏ hàng!');</SCRIPT> ");

    }
    protected void DatMua(object s, CommandEventArgs e)
    {
        var idpr = e.CommandName;
        var cart = (Cart)Session["cart"];
        if (cart == null)
        {
            cart = new Cart();
        }
        cart.AddPro(idpr, 1);
        Session.Add("cart", cart);
        Response.Write("<SCRIPT language='JavaScript'>alert('Đã thêm vào giỏ hàng!');</SCRIPT> ");
    }
}